﻿package Cain.MkMc 
{
	import flash.display.BlendMode;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import com.greensock.TweenLite
	/**
	 * 全景遮罩 v1.01 2010.09.24
	 * @author Cain
	 */
	public class AllMk extends Sprite{
		private var _root:Sprite; //root
		private var mkAlpha:Number; //透明度
		private var mkColor:int; //顏色
		private var in_s:Number; //淡入時間
		private var sp:Sprite;
		private var mk:Bk;//遮罩色塊
		 /**
		 * 建構
		 * @param	_mc 場景上的顯示物件
		 * @param	_alpha 透明度
		 * @param	_color 顏色
		 * @param	_s 顯示秒速
		 * @param	_mdswf 是否為置中全螢幕
		 */
		public function AllMk(_mc:DisplayObject,_alpha:Number = .5,_color:uint = 0,_s:Number=.5) 
		{
			_root = Sprite(_mc.root);
			mkAlpha = _alpha;
			mkColor = _color;
			in_s = _s;
			setup();
		}
		private function setup():void
		{
			var ww:Number = _root.stage.stageWidth;
			var hh:Number = _root.stage.stageHeight;
			mk = new Bk(ww, hh, mkColor);
			addChild(mk);
			addEventListener(Event.ADDED_TO_STAGE, addthis);
		}
		
		private function addthis(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, addthis);
			addEventListener(Event.REMOVED_FROM_STAGE, renovethis);
			stage.addEventListener(Event.RESIZE, onRESIZE);
			init();
			
		}
		
		private function onRESIZE(e:Event = null):void 
		{
			mk.width = _root.stage.stageWidth;
			mk.height = _root.stage.stageHeight;
		}
		/**
		 * 進入
		 */
		public function init():void
		{
			onRESIZE();
			mk.alpha = 0;
			_root.addChild(this);
			TweenLite.to(mk, in_s, { alpha:mkAlpha } );
		}
		/**
		 * 退場
		 * @param	_s 時間
		 */
		public function unload(_s:Number=.5):void 
		{
			TweenLite.to(mk, _s, { alpha:0,onComplete:end } );
		}
		
		private function end():void
		{
			stage.removeEventListener(Event.RESIZE, onRESIZE);
			_root.removeChild(this);
		}
		private function renovethis(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, renovethis);
		}
	}
	
}